from sqlalchemy import Column,String,Integer,create_engine
from sqlalchemy.orm import sessionmaker
from sqlalchemy.ext.declarative import declarative_base

Base=declarative_base()
class math(Base):
    __tablename__="math"

    id=Column(String(20),primary_key=True)
    name=Column(String(20))
    ms=Column(Integer)

engine=create_engine("mysql+mysqlconnector://root:132786@localhost:3306/score")
DBSession=sessionmaker(bind=engine)
session=DBSession()

x=session.query(math.id,math.name,math.ms).all()
print(type(x))
print(x)
for i in x:
    print(i)

session.close()













# # 导入使用到的库
# from sqlalchemy import Column, String ,Integer,create_engine
# from sqlalchemy.orm import sessionmaker
# from sqlalchemy.ext.declarative import declarative_base
# # 创建对象的基类:
# Base = declarative_base()
# # 定义对象math:
# class math(Base):
#     # 对应表名:
#     __tablename__ = 'math'

#     # 字段结构:
#     id = Column(String(20), primary_key=True)
#     name = Column(String(20))
#     ms = Column(Integer)    

# # 初始化数据库连接:
# engine = create_engine('mysql+mysqlconnector://root:password@localhost:3306/score')
# # 创建DBSession类型:
# DBSession = sessionmaker(bind=engine)
# # 创建Session:
# session = DBSession()
# # 创建Query查询，返回所有行:
# user = session.query(math.id,math.name,math.ms).all()
# # 输出类型、值:
# print('type:', type(user))
# for x in user:
#     print(x)
# # 关闭Session:
# session.close()